package com.monkeyboy.controller;

import com.monkeyboy.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Gavin
 * @date 2020.09.01 11:14
 */
@RestController
public class SearchController {
    @Autowired
    private SearchService searchService;

    //爬取京东的数据放入es里面
    @GetMapping("/parseJD/{keyWord}")
    public Boolean parseJD(@PathVariable("keyWord") String keyWord) throws Exception {
        return searchService.parseJDContent(keyWord);
    }

    //爬取爱回收的数据放入es里面
    @GetMapping("/scrapAihuishou")
    public Boolean scrapAihuishou() throws Exception {
        return searchService.parseAihuishouContent();
    }

    /**
     * 搜索
     *
     * @param keyWord
     * @param pageNo
     * @param pageSize
     * @return
     * @throws Exception
     */
    @GetMapping("/search/{keyWord}/{pageNo}/{pageSize}")
    public Object parseJD(@PathVariable("keyWord") String keyWord,
                          @PathVariable("pageNo") int pageNo,
                          @PathVariable("pageSize") int pageSize) throws Exception {
        return searchService.searchPage(keyWord, pageNo, pageSize);
    }

    /**
     * 搜索+高亮显示
     *
     * @param keyWord
     * @param pageNo
     * @param pageSize
     * @return
     * @throws Exception
     */
    @GetMapping("/searchhighlight/{keyWord}/{pageNo}/{pageSize}")
    public Object parseJDHighlight(@PathVariable("keyWord") String keyWord,
                                   @PathVariable("pageNo") int pageNo,
                                   @PathVariable("pageSize") int pageSize) throws Exception {
        return searchService.searchPageHighlight(keyWord, pageNo, pageSize);
    }
}
